package com.teufandsub.socialproximity.gui;

import android.content.Intent;
import android.os.Bundle;
import android.widget.ListView;

import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import com.teufandsub.socialproximity.R;
import com.teufandsub.socialproximity.controller.Controller;
import com.teufandsub.socialproximity.services.BackgroundService;

/**
 * @author Bastien Mathias <bastienmathias@gmail.com>
 * @author Antoine Teuf <antoine.teuf@gmail.com>
 * @version 1.0
 * @since 2013-05-22
 * 
 * Activity to display user found after a research.
 */

public class SearchResultActivity extends SocialProxActivity{
	
	private ListView resultList;
	private FriendResultAdapter adapter;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_search_result);
		
		controller = Controller.getInstance();
		adapter = new FriendResultAdapter(this, controller.getResultList());
		
		resultList = (ListView) findViewById(R.id.result_list);
		resultList.setAdapter(adapter);
	}
	
	public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
		MenuInflater inflater = this.getSupportMenuInflater();
		inflater.inflate(R.menu.main_menu, menu);
		return true;
	};
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		Intent intent;
		switch(item.getItemId()){
			case R.id.action_close:
				intent = new Intent(this, IndexActivity.class);
				startActivity(intent);		
				stopService(new Intent(this, BackgroundService.class));
				moveTaskToBack(true);	
				break;
			case R.id.action_home_button:
				intent = new Intent(this, HomeActivity.class);
				startActivity(intent);
				break;
			case R.id.action_home:
				intent = new Intent(this, HomeActivity.class);
				startActivity(intent);
				break;
			case R.id.action_log_out: 
				controller.disconnect(this);
				break;
			default:;
		}
		return true;
	}
}
